﻿using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using EnvDTE80;

namespace TSVNAddin.Core
{
	public class SelectedItemsAdapter
	{
		private readonly DTE2 _Dte;

		public SelectedItemsAdapter(DTE2 dte)
		{
			_Dte = dte;
		}

		public virtual List<string> GetSelectedPaths()
		{
			List<string> paths = new List<string>();
			for (int i = 1; i <= _Dte.SelectedItems.Count; i++ )
			{
				var selectedItem = _Dte.SelectedItems.Item(i);
				string path = GetPath(selectedItem);
				paths.Add(path);
			}

			return paths;
		}

		private string GetPath(SelectedItem selectedItem)
		{
			if (selectedItem.ProjectItem != null)
				return selectedItem.ProjectItem.get_FileNames(0);

			if (selectedItem.Project != null)
				return selectedItem.Project.FullName;

			return selectedItem.DTE.Solution.FileName;
		}

		public virtual bool IsMultiSelect()
		{
			return _Dte.SelectedItems.MultiSelect;
		}
	}
}
